package util

import (
	"encoding/json"
	"fmt"
	"gpt-api/framework/log"
	"time"
)

func Vivo(reqId, creId string) {
	var (
		result struct {
			Code int         `json:"code"`
			Msg  string      `json:"msg"`
			Data interface{} `json:"data"`
		}
		DataLists []DataList
	)

	sp := DataList{
		CvType:     "SUBMIT",
		CvTime:     time.Now().UnixNano(),
		RequestID:  reqId,
		CreativeID: creId,
		ExtParam:   Es{UnionID: "1111", PayAmount: "10000"},
	}
	DataLists = append(DataLists, sp)
	var key string
	key = RoundNum()
	urls := "https://marketing-api.vivo.com.cn/openapi/v1/advertiser/behavior/upload"
	access_token := "291c62ae982a88cac87b86d6a3bb40c0d8343e46a6e09f96757d1c7a9d5850ba"
	times := time.Now().UnixNano() / 1000000
	url := fmt.Sprintf("%s?access_token=%s&timestamp=%d&nonce=%s&advertiser_id=%s", urls, access_token, times, key, "6e48f5d40369db3a7bb5")
	//log.Info("ViVo_URL", log.Var("ViVo_URL", url))

	//url := "https://sapi.ads.oppomobile.com/v1/clue/sendData"

	params := map[string]interface{}{}
	params["srcType"] = "Web"
	params["pageUrl"] = "variety.34sport.cn/bazi"
	params["srcId"] = "ds-202302242921"

	params["nonce"] = key
	params["dataList"] = DataLists

	ms, _ := json.Marshal(params)
	msg, code, respHeader, err := HttpReq(url, "POST", nil, nil, ms, &result)
	if err != nil {
		log.Error("ViVo_HttpReq_Error", log.Var("ViVo_HttpReq_Error", err))
	}
	log.Info("ViVo归因上传", log.Var("msg", msg), log.Var("code", code), log.Var("respHeader", respHeader))
	//fmt.Print("result\n", msg, "\n", code, "\n", respHeader)

}

func Vivo2(reqId, creId string) {
	var (
		result struct {
			Code int         `json:"code"`
			Msg  string      `json:"msg"`
			Data interface{} `json:"data"`
		}
		DataLists []DataList
	)

	sp := DataList{
		CvType:     "SUBMIT",
		CvTime:     time.Now().UnixNano(),
		RequestID:  reqId,
		CreativeID: creId,
		ExtParam:   Es{UnionID: "1111", PayAmount: "10000"},
	}
	DataLists = append(DataLists, sp)
	var key string
	key = RoundNum()
	//fmt.Println("key", key)
	urls := "https://marketing-api.vivo.com.cn/openapi/v1/advertiser/behavior/upload"
	access_token := "7444dd48b8ba58b546c9f528d0ac6017988a743bb280be5854e032ea33dd690b"
	times := time.Now().UnixNano() / 1000000
	url := fmt.Sprintf("%s?access_token=%s&timestamp=%d&nonce=%s&advertiser_id=%s", urls, access_token, times, key, "1d14534d058f98d5ffe3")
	//log.Info("ViVo_URL", log.Var("ViVo_URL", url))

	//url := "https://sapi.ads.oppomobile.com/v1/clue/sendData"

	params := map[string]interface{}{}
	params["srcType"] = "Web"
	params["pageUrl"] = "variety.34sport.cn/bazi"
	params["srcId"] = "ds-202302247138"

	params["nonce"] = key
	params["dataList"] = DataLists

	ms, _ := json.Marshal(params)
	msg, code, respHeader, err := HttpReq(url, "POST", nil, nil, ms, &result)
	if err != nil {
		log.Error("ViVo_HttpReq_Error", log.Var("ViVo_HttpReq_Error", err))
	}
	log.Info("ViVo归因上传", log.Var("msg", msg), log.Var("code", code), log.Var("respHeader", respHeader))
	//fmt.Print("result\n", msg, "\n", code, "\n", respHeader)

}
func Vivo3(reqId, creId string) {
	var (
		result struct {
			Code int         `json:"code"`
			Msg  string      `json:"msg"`
			Data interface{} `json:"data"`
		}
		DataLists []DataList
	)

	sp := DataList{
		CvType:     "SUBMIT",
		CvTime:     time.Now().UnixNano(),
		RequestID:  reqId,
		CreativeID: creId,
		ExtParam:   Es{UnionID: "1111", PayAmount: "10000"},
	}
	DataLists = append(DataLists, sp)
	var key string
	key = RoundNum()
	//fmt.Println("key", key)
	urls := "https://marketing-api.vivo.com.cn/openapi/v1/advertiser/behavior/upload"
	access_token := "a52fa7275cc1d85c07d7b79ba44e28c052f436d8cbc979a5bb640b07807ee1ab"
	times := time.Now().UnixNano() / 1000000
	url := fmt.Sprintf("%s?access_token=%s&timestamp=%d&nonce=%s&advertiser_id=%s", urls, access_token, times, key, "98214f57c475c6c61fde")
	//log.Info("ViVo_URL", log.Var("ViVo_URL", url))

	//url := "https://sapi.ads.oppomobile.com/v1/clue/sendData"

	params := map[string]interface{}{}
	params["srcType"] = "Web"
	params["pageUrl"] = "variety.34sport.cn/bazi"
	params["srcId"] = "ds-202302248607"

	params["nonce"] = key
	params["dataList"] = DataLists

	ms, _ := json.Marshal(params)
	msg, code, respHeader, err := HttpReq(url, "POST", nil, nil, ms, &result)
	if err != nil {
		log.Error("ViVo_HttpReq_Error", log.Var("ViVo_HttpReq_Error", err))
	}
	log.Info("ViVo归因上传", log.Var("msg", msg), log.Var("code", code), log.Var("respHeader", respHeader))
	//fmt.Print("result\n", msg, "\n", code, "\n", respHeader)

}

type DataList struct {
	CreativeID string `json:"creativeId"`
	CvParam    string `json:"cvParam"`
	CvTime     int64  `json:"cvTime"`
	CvType     string `json:"cvType"`
	UserID     string `json:"userId"`
	DlrSrc     string `json:"dlrSrc"`
	UserIDType string `json:"userIdType"`
	RequestID  string `json:"requestId"`
	CvCustom   string `json:"CvCustom"`
	ExtParam   Es     `json:"extParam"`
	//} `json:"dataList"`
}

type Es struct {
	PayAmount string `json:"payAmount"`
	UnionID   string `json:"unionId"`
}
